﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;
using ZhouYu.NewWorld.Web.Models;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class BackcolumnController : Controller
    {
        //注入
        private IBackcolumnService _backcolumnService;
        public BackcolumnController(IBackcolumnService backcolumnService)
        {
            _backcolumnService = backcolumnService;
        }

        #region 显示数据
        /// <summary>
        /// 显示数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public JsonResult GetBackcolumnPageList(int page, int limit, string name)
        {
            ResponseResult result = _backcolumnService.GetBackcolumnPageList(page, limit, name);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public JsonResult DelBackcolumn(int id)
        {
            ResponseResult ResponseResult = new ResponseResult();
            ResponseResult.Success = _backcolumnService.Deletes(id);
            return Json(ResponseResult);
        }
        #endregion

        #region 添加和修改
        public JsonResult AddBackcolumn(Backcolumn backcolumn)
        {
            ResponseResult responseResult = new ResponseResult();
            //当前时间
            backcolumn.BackColumn_CreateTime = DateTime.Now;
            backcolumn.BackColumn_UpdateTime = DateTime.Now;
            //根据ID是否为空判断是添加还是编辑操作
            if (backcolumn.BackColumn_Id > 0)
            {
                //实例化对象接收根据ID查询返回的一个对象
                Backcolumn dd = _backcolumnService.Query(a => a.BackColumn_Id == backcolumn.BackColumn_Id);
                
                //逐个赋值
                //tour.BackColumn_Id = backcolumn.BackColumn_Id;
                dd.BackColumn_ParentId = backcolumn.BackColumn_ParentId;
                dd.BackColumn_Name = backcolumn.BackColumn_Name;
                dd.BackColumn_Url = backcolumn.BackColumn_Url;
                
        
              
                //编辑旅游路线
                responseResult.Success = _backcolumnService.Update(dd);
                responseResult.msg = responseResult.Success ? "编辑成功" : "编辑失败";
            }
            else
            {
                //添加旅游路线
                responseResult.Success = _backcolumnService.Add(backcolumn);
                responseResult.msg = responseResult.Success ? "添加成功" : "添加失败";
            }
            return Json(responseResult);
        }

        #endregion

        public ActionResult Index()
        {
            return View();
        }
    }
}